package v1

import (
	"fmt"
	"gitee.com/daka1004/devops-runner/common/logs"
	"gitee.com/daka1004/devops-runner/dto/request"
	"gitee.com/daka1004/devops-runner/modules/setting"
	"github.com/gin-gonic/gin"
	"net/http"
)

//
//// SoftwareFactoryController 对应Java中的SoftwareFactoryController
//type SoftwareFactoryController struct {
//	softwareFactoryService service.SoftwareFactoryService
//}
//
//// NewSoftwareFactoryController 创建新的控制器实例
//func NewSoftwareFactoryController() *SoftwareFactoryController {
//	return &SoftwareFactoryController{
//		softwareFactoryService: service.SoftwareFactoryService{},
//	}
//}

// Test 处理GET请求
func (c *BaseApi) Test(ctx *gin.Context) {
	ctx.JSON(http.StatusOK, gin.H{
		"message": "success",
	})
} // Test 处理GET请求
func (c *BaseApi) Test2(ctx *gin.Context) {
	url := fmt.Sprintf("ws://%s:%d/ssh/agentLogger?nodeUUID=%s&executeLoggerUUID=%s", setting.Setting.ServerIP, 8280, "123", "456")
	//url := fmt.Sprintf("ws://%s:%d/ssh/agentLogger?executingId=%s", setting.Setting.ServerIP, 8280, req.ExecuteID)
	//url := fmt.Sprintf("ws://%s:%d/ssh/logger?nodeUUID=%s&executeLoggerUUID=%s", setting.Setting.ServerIP, 8280, req.NodeUuid, req.ExecuteID)
	//manager, err := mq.NewWebSocketManager(url)
	logs.Infof("url is : %v\n", url)
	ctx.JSON(http.StatusOK, gin.H{
		"message": "success",
	})
}

// ThreeInOneStaticAnalysis 处理三合一静态分析请求
func (c *BaseApi) ThreeInOneStaticAnalysis(ctx *gin.Context) {
	var threeInOneModel request.ThreeInOneModel
	if err := ctx.BindJSON(&threeInOneModel); err != nil {
		ctx.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}

	commandBean := softwareFactoryService.ThreeInOneStaticAnalysis(threeInOneModel)
	ctx.JSON(http.StatusOK, commandBean)
}

// ThreeInOneMeasurement 处理三合一度量请求
func (c *BaseApi) ThreeInOneMeasurement(ctx *gin.Context) {
	var measurementModel request.MeasurementModel
	if err := ctx.BindJSON(&measurementModel); err != nil {
		ctx.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}

	commandBean := softwareFactoryService.ThreeInOneMeasurement(measurementModel)
	ctx.JSON(http.StatusOK, commandBean)
}
